package com.ruoyi.attendance.service.impl;

import java.util.List;

import com.ruoyi.common.enums.SignStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.attendance.mapper.AttendanceRecordMapper;
import com.ruoyi.attendance.domain.AttendanceRecord;
import com.ruoyi.attendance.service.IAttendanceRecordService;

/**
 * 考勤信息Service业务层处理
 * 
 * @author Weiney
 * @date 2025-03-03
 */
@Service
public class AttendanceRecordServiceImpl implements IAttendanceRecordService 
{
    @Autowired
    private AttendanceRecordMapper attendanceRecordMapper;

    /**
     * 查询考勤信息
     * 
     * @param userId 学生ID
     * @return 考勤信息
     */
    @Override
    public AttendanceRecord selectAttendanceRecordByUserIdAndCourseRecordId(Long userId, Long courseRecordId)
    {
        return attendanceRecordMapper.selectAttendanceRecordByUserIdAndCourseRecordId(userId, courseRecordId);
    }

    /**
     * 查询考勤信息列表
     * 
     * @param attendanceRecord 考勤信息
     * @return 考勤信息
     */
    @Override
    public List<AttendanceRecord> selectAttendanceRecordList(AttendanceRecord attendanceRecord)
    {
        return attendanceRecordMapper.selectAttendanceRecordList(attendanceRecord);
    }

    /**
     * 【学生】查询考勤信息列表
     *
     * @param attendanceRecord 考勤信息
     * @return 考勤信息
     */
    @Override
    public List<AttendanceRecord> selectAttendanceRecordListForStudent(AttendanceRecord attendanceRecord)
    {
        return attendanceRecordMapper.selectAttendanceRecordListForStudent(attendanceRecord);
    }

    /**
     * 【教师】查询当前课程下的所有学生考勤情况
     * @param attendanceRecord
     * @return
     */
    @Override
    public List<AttendanceRecord> selectAttendanceRecordListForTeacher(AttendanceRecord attendanceRecord)
    {
        return attendanceRecordMapper.selectAttendanceRecordListForTeacher(attendanceRecord);
    }

    /**
     * 考勤详情查询
     * @param attendanceRecord
     * @return
     */
    @Override
    public List<AttendanceRecord> selectAttendanceRecordListForDetail(AttendanceRecord attendanceRecord)
    {
        // 筛选 签到状态不是 未签到的学生
        SignStatus signStatus = SignStatus.NOT_SIGNED;
        attendanceRecord.setSignStatus(signStatus.getCode());
        return attendanceRecordMapper.selectAttendanceRecordListForDetail(attendanceRecord);
    }

    /**
     * 新增考勤信息
     * 
     * @param attendanceRecord 考勤信息
     * @return 结果
     */
    @Override
    public int insertAttendanceRecord(AttendanceRecord attendanceRecord)
    {
        return attendanceRecordMapper.insertAttendanceRecord(attendanceRecord);
    }

    /**
     * 修改考勤信息
     * 
     * @param attendanceRecord 考勤信息
     * @return 结果
     */
    @Override
    public int updateAttendanceRecord(AttendanceRecord attendanceRecord)
    {
        return attendanceRecordMapper.updateAttendanceRecord(attendanceRecord);
    }

    /**
     * 批量删除考勤信息
     * 
     * @param courseRecordIds 需要删除的考勤信息主键
     * @return 结果
     */
    @Override
    public int deleteAttendanceRecordByCourseRecordIds(Long[] courseRecordIds)
    {
        return attendanceRecordMapper.deleteAttendanceRecordByCourseRecordIds(courseRecordIds);
    }

    /**
     * 删除考勤信息信息
     * 
     * @param courseRecordId 考勤信息主键
     * @return 结果
     */
    @Override
    public int deleteAttendanceRecordByCourseRecordId(Long courseRecordId)
    {
        return attendanceRecordMapper.deleteAttendanceRecordByCourseRecordId(courseRecordId);
    }
}
